<?php
/**
 * Created by PhpStorm.
 * User: FredGui
 * Date: 2017/1/9
 * Time: 19:23
 */

namespace Gmm\App\Mvc\Home\Controllers;


use Gmm\App\Mvc\Home\Model\User as User;
use Gmm\App\Mvc\Home\Model;
use Phalcon\Mvc\Controller;


class IndexController extends Controller
{

    public function indexAction(){
        echo "<pre>";
       // $result = User::findFirst();
       // echo $result->count();exit;

        $manage = $this->modelsManager;
        $name = 'test';
        $phql = "select * from Gmm\App\Mvc\Home\Model\User where user_name = :name:";
        $users = $manage->executeQuery($phql,
            ['name' => 'test']
            );
        foreach ($users as $uk => $user){
            echo '用户名' . $user->user_name . "<br />";
        }

        $phql = 'select * from Gmm\App\Mvc\Home\Model\User ';
       // print_r($users);
       exit;
    }

    public function showAction(){
//        $phql = "select * from Gmm\App\Mvc\Home\Model\WechatAccount order by search_id limit 0,10";
//        $data = $this -> modelsManager -> executeQuery($phql);
//
//        foreach ($data as $uk => $user){
//            echo '用户名' . $user->wechat_name . "<br />";
//        }
        $wechatModel = new Model\WechatAccount();
        $wechats = Model\WechatAccount::query()

            ->limit(10)

            ->execute();

        foreach ($wechats->toArray() as $uk => $user){
            echo '用户名' . $user['wechat_id'] . "<br />";
        }

       echo 'show';exit;
    }

    public function editAction(){

        echo '无权访问';

        $this->dispatcher->forward(
            [
                'module'     => 'home',
                'controller' => 'index',
                'action'     => 'index',
            ]
        );
    }
    public function saveAction(){
        echo 'yoyoyoi';exit;
        echo 'name:', $this->persistent->name;
    }
    public function firstAction(){
        echo 1111111111111;
    }

}
